<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>同源策略</title>
</head>
<body>
    <button id="btn">点击发送请求</button>
    <script>
        let btn = document.querySelector('button');

        btn.onclick = function(){
            let x = new XMLHttpRequest();
            x.open('post', 'http://127.0.0.1/server');
            x.send();
            x.onreadystatechange = function(){
                if(x.readyState ===4){
                    console.log(x.response);
                }
            }
        }
    </script>
</body>
</html>